﻿using System;

namespace AnB.Common
{
    public class CyclicCounter
    {
        public CyclicCounter(long min = 0, long max = long.MaxValue)
        {
            Min = min;
            Max = max;
            Current = Min;
        }

        long Min;
        long Max;
        long Current;
        public long Next
        {
            get
            {
                lock (this)
                {
                    long val = Current;
                    if (Current >= Max)
                    {
                        Current = Min;
                    }
                    else
                    {
                        Current += 1;
                    }
                    return val;
                }
            }
        }
    }
}
